home *** CD-ROM | disk | FTP | other *** search
-
- /* FROUNDL Round float n to precision p, return
- | ~~~~~~~ long = n * 10^p.
- */
-
- #include <math.h>
-
- long froundl(const double n, const int p)
- {
- long r;
-
- r = (long)(n * pow(10.0, (double)(p+1)));
- if ((r % 10L) > 4L)
- r += 5L;
- return(r / 10L);
- }
-
- void main() /* Test driver */
- {
- double val;
- long result;
-
- val = 3.141592654;
- printf("Rounding the value: %10.8lf\n", val);
-
- printf("to 2 places: %ld\n", froundl(val, 2));
- printf("to 3 places: %ld\n", froundl(val, 3));
- printf("to 4 places: %ld\n", froundl(val, 4));
- printf("to 5 places: %ld\n", froundl(val, 5));
- }
-